package com.h1909d.weinfo.ui.fragment;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.h1909d.weinfo.R;
import com.h1909d.weinfo.base.BaseLazyFragment;
import com.h1909d.weinfo.bean.SectionsBean;
import com.h1909d.weinfo.presenter.DailyNewsPresenter;
import com.h1909d.weinfo.presenter.SectionsPresenter;
import com.h1909d.weinfo.ui.adapter.RlvSectionAdapter;
import com.h1909d.weinfo.view.SectionsView;

import java.util.ArrayList;

public class SectionsFragment extends BaseLazyFragment<SectionsPresenter> implements SectionsView {

    private RecyclerView mRlv;
    private ArrayList<SectionsBean.DataBean> dataBeans;
    private RlvSectionAdapter rlvSectionAdapter;

    /**
     *
     * @return
     */
    public static SectionsFragment getInstance(){
        SectionsFragment fragment = new SectionsFragment();
        return fragment;
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {
        mPresenter.getLastesSection();
    }

    @Override
    protected SectionsPresenter initPresenter() {
        return new SectionsPresenter();
    }

    @Override
    protected void initView(View view) {
        mRlv = view.findViewById(R.id.rlv);

        mRlv.setLayoutManager(new GridLayoutManager(getActivity(), 2));
        dataBeans = new ArrayList<>();
        rlvSectionAdapter = new RlvSectionAdapter(getActivity(), dataBeans);
        mRlv.setAdapter(rlvSectionAdapter);

    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_sections;
    }

    @Override
    public void setData(SectionsBean sectionsBean) {
        rlvSectionAdapter.setData(sectionsBean);
    }
}
